$(function(){
    var xml = '';
    $.ajax({
        url:"/plug_in/sales/xml/ChinaArea.xml",
        async:false,
        success:function(data){
            xml = data;
            var pro = $(data).find('province');
            $(pro).each(function(){
               var pro_id = $(this).attr('provinceID');
                var pro_name = $(this).attr('province');
                // console.log(pro_name);
                $('#province').append("<option value="+pro_id+">"+pro_name+"</option>");
            });
        },
        dataType:'xml'
    });

    $('#province').change(function(){
        $("#city").empty();
        $('#city').append("<option>请选择城市</option>");
        var pro_id = $(this).val();
        var city = $(xml).find('province[provinceID='+pro_id+']').find('City');
        $(city).each(function(){
            var city_id = $(this).attr('CityID');
            var city_name = $(this).attr('City');
            $('#city').append("<option value="+city_id+">"+city_name+"</option>");
        })
    });

    $('#city').change(function(){
        $('#piecearea').empty();
       var city_id = $(this).val();
       var area = $(xml).find('City[CityID='+city_id+']').find('Piecearea');
       $(area).each(function(){
          var area_id = $(this).attr('PieceareaID');
          var area_name = $(this).attr('Piecearea');
          $('#piecearea').append("<option value="+area_id+">"+area_name+"</option>");
       });
    });

    $("#province,#city").trigger('change');

})